define(['jquery', 'cookie'], () => {
    class Header {
        constructor() {
            this.loadHTML().then(() => {
                this.caLaCartCount()
                this.headerLogin()
                this.quit()
            })
        }
        loadHTML() {
            return new Promise(resolve => {
                $('header').load('/html/modules/header.html', resolve)
            })
        }
        // $('header').load('/html/modules/header.html')    
        //^计算总数量
        caLaCartCount() {
            let count = 0
            let cart = localStorage.getItem('cart')
            cart = JSON.parse(cart)
            if (cart) {
                count = cart.reduce((num, shop) => num + shop.count, 0)
            }
            $('.frNum').html(count)
            // console.log(count)
            $('#cart-count').html(count)
        }
        //^登陆改变样式   
        headerLogin() {
            if ($.cookie('name')) {
                $('.navbar-login').hide()
                $('.navbar-register').hide()
                $('.me').removeClass('hide').html(`欢迎您,${$.cookie('name')}`)
                $('.tuiChu').removeClass('hide')
                // console.log('123')
            }
        }
        //^点击退出
        quit(){
            const that = this
            $('.tuiChu').on('click',()=>{
                $.removeCookie('name',{ path: '/'})
                that.loadHTML()
            })
        }
    }
    return new Header()
})